<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>场地管理</title>
		<link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css" />
		<link rel="stylesheet" type="text/css" href="${s.base}/css/base/theme/theme.css" />
	</head>
	<body class="wrap-container clearfix">
	<!--<style>-->
		<!--.layui-table td, .layui-table th{text-align:center;}-->
	<!--</style>-->
	<div class="column-content-detail">
		<form class="layui-form">
			<div class="search-cont clearfix" id="tool">
				<div class="operation-btn-cont">
					<div class="operright cyt-retract-close hideMenu">
						收起筛选<i class="iconfont">&#xe658;</i>
					</div>
					<div class="operright cyt-retract-open showMenu" style="display: none;">
						展开筛选<i class="iconfont">&#xe936;</i>
					</div>
					<button class="layui-btn layui-btn-normal layui-btn-mid " type="button" data-tab-name="场地添加"  id="bulidAddOrEdit" ><i class="iconfont marr5">&#xe65e;</i>添加</button>
				<button class="layui-btn layui-btn-normal layui-btn-mid down-all" type="button"><i class="iconfont marr5">&#xe6a6;</i>展开</button>
				<button class="layui-btn layui-btn-normal layui-btn-mid up-all" type="button"><i class="iconfont marr5">&#xe66f;</i>收起</button>
				<div class="triangle-bottom"></div>
			<div class="triangle-top"></div>
	</div>
	<div class="search-details">
		<div class="layui-form-item marb5">
			<div class="layui-inline">
				<label class="layui-form-label w75">场地名称：</label>
				<div class="layui-input-inline">
					<input type="text" name="name" id="name" placeholder="请输入场地名称" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label w75">场地分类：</label>
				<div class="layui-input-inline">
					<select name="bulidClass" id="bulidClass">

					</select>
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label w75">场地用途：</label>
				<div class="layui-input-inline">
					<select name="bulidType" id="bulidType">

					</select>
				</div>
			</div>
			<div class="layui-inline marl8">
				<button class="layui-btn layui-btn-normal" type="button" lay-submit="" id="seacherBtn">搜索</button>
				<button class="layui-btn layui-btn-normal" type="reset" >重置</button>
			</div>
		</div>
	</div>
	</div>
	    </form>
			<div class="layui-form" id="table-list">
				<table lay-filter="entityList" class="layui-table layui-formcy-list-table" id="entityList"></table>
			</div>
	</div>
	<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
	<script>
        var applyId='${applyId}';
        layui.use(['jquery','treetable','form','baseutil','page','table'],function(){
            var $ = layui.jquery
				,baseutil = layui.baseutil
				,treetable = layui.treetable
				,page = layui.page
				,form = layui.form
				, layer = layui.layer;
            var renderTable =function () {
                var name = $('#name').val();
                var bulidType = $('#bulidType').val();
                var bulidClass = $('#bulidClass').val();
                page.initDict('bulidClass,bulidType', function (dictData) {
                    baseutil.post("/wb/wxwbbulid/findList", {
                        "name": name,
                        "bulidType": bulidType,
                        "bulidClass": bulidClass,
                        "applyId": applyId
                    }, function (result) {
                        var data = [];
                        if (0 == result.code) {
                            for (var i = 0; i < result.data.length; i++) {
                                var obj = result.data[i];
                                var d = {};
                                d.id = obj.id;
                                d.name = obj.name;
                                if (obj.parentId == null || obj.parentId == "" || (name != null && name != "")||((bulidType != null && bulidType != ""))||((bulidClass != null && bulidClass != ""))) {
                                    d.pid = 0;
                                } else {
                                    d.pid = obj.parentId;
                                }
                                d.sort = obj.sort;
                                d.code = obj.code;
                                d.remarks = obj.remarks;
                                d.bulidClass = page.aceeptDictContentName(dictData, "bulidClass", obj.bulidClass);
                                if (obj.bulidClass =="3") {
                                    d.bulidType = page.aceeptDictContentName(dictData, "bulidType", obj.bulidType);
                                } else {
                                    d.bulidType = '-';
                                }
                                d.bulidClassCode = obj.bulidClass;
                                data.push(d);
                            }
                            treetable.render({
                                elem: '#entityList',
                                data: data,
                                field: 'name',
                                is_checkbox: true,
                                cols: [
                                    {
                                        field: 'name',
                                        title: '场地名称',
                                        width: '25%',
                                        align: 'center'
                                    }, {
                                        field: 'sort',
                                        title: '排序',
                                        width: '5%',
                                        align: 'center'
                                    }, {
                                        field: 'bulidClass',
                                        title: '场地分类',
                                        align: 'center',
                                        width: '15%'
                                    }, {
                                        field: 'bulidType',
                                        title: '场地用途',
                                        align: 'center',
                                        width: '15%'
                                    }, {
                                        field: 'remarks',
                                        title: '备注',
                                        width: '20%',
                                        align: 'center'
                                    }, {
                                        title: '操作',
                                        width: '25%',
                                        align: 'center',
                                        template: function (d) {
                                            var tem = [];
                                            if (d.bulidClassCode == '3') {
                                                tem.push('<a class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-green"  lay-filter="edit">编辑</a>');
                                                tem.push('<button class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-red" lay-filter="delete">删除</button>');
                                            } else {
                                                tem.push('<a class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-purple"  lay-filter="add">添加</a>');
                                                tem.push('<a class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-green"  lay-filter="edit">编辑</a>');
                                                tem.push('<button class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-red" lay-filter="delete">删除</button>');
                                            }
                                            return tem.join(' <font> </font> ')
                                        },
                                    }
                                ]
                            });
                        } else {
                            top.layer.msg(result.msg);
                        }
                    });
                });
            };
            page.initDict("bulidType,bulidClass", function (dictData) {
                page.showDict($("#bulidType"), page.aceeptDictContentList(dictData, "bulidType"), "请选择场地用途");
                page.showDict($("#bulidClass"), page.aceeptDictContentList(dictData, "bulidClass"), "请选择场地分类");
            });
            renderTable();
            treetable.on('treetable(add)', function (data) {
                page.editPopup("/wb/wxwbbulid/getAdd?parentId="+data.item.id+"&applyId="+applyId, "场地添加","800px","600px");
            });

            treetable.on('treetable(addroom)', function (data) {
                page.editPopup("/wb/wxwbroom/getAdd?bulidId="+data.item.id+"&applyId="+applyId, "房间添加","800px","600px");
            });

            treetable.on('treetable(edit)', function (data) {
                page.editPopup("/wb/wxwbbulid/getAdd?id=" + data.item.id+"&applyId="+applyId, "场地编辑","800px","600px");
            });
            treetable.on('treetable(editroom)', function (data) {
                page.editPopup("/wb/wxwbroom/getAdd?id=" + data.item.id+"&applyId="+applyId, "房间编辑","800px","600px");
            });
            treetable.on('treetable(delete)', function (data) {
                page.delete("/wb/wxwbbulid/remove", {
                    "id":data.item.id,
                    "bulidClass":data.item.bulidClassCode,
                    "_method": "DELETE"
                }, "确定删除该场地吗？", function (data) {
                    top.layer.msg(data);
                    window.location.reload();
                });
            });
            treetable.on('treetable(deleteroom)', function (data) {
                page.delete("/wb/wxwbroom/remove", {
                    "id":data.item.id,
                    "_method": "DELETE"
                }, "确定删除该房间吗？", function (data) {
                    top.layer.msg(data);
                    window.location.reload();
                });
            });

            //监听行工具事件
            treetable.on('tool(test-tree-table)', function (obj) {
                var layEvent = obj.event,
                    data = obj.data;
                if (layEvent === 'del') { //删除
                    page.delete("/wb/wxwbbulid/remove", {
                        "id": data.item.id,
                        "_method": "DELETE"
                    }, "确定删除该场地吗？", function (data) {
                        top.layer.msg(data);
                        window.location.reload();
                    });
                }
            });

            form.on('switch(status)', function (data) {
                layer.msg('监听状态操作');
            })

            $('#seacherBtn').click(function(){
                renderTable();
            });

            $('.up-all').click(function(){
                treetable.all('up');
            });

            $('.down-all').click(function(){
                treetable.all('down');
            });

            $('.get-checked').click(function(){
                console.dir(treetable.all('checked'));
            });

            $("#bulidAddOrEdit").bind("click",function () {
                page.editPopup("/wb/wxwbbulid/getAdd?applyId="+applyId, "场地添加","800px","600px");
            });
        });
	</script>
	</body>

</html>